//
//  Orders.swift
//  Fancyswap
//
//  Created by Cheikh Bara on 2015-04-06.
//  Copyright (c) 2015 Jonathan Muschalle. All rights reserved.
//

import UIKit

class Orders {
    
    var id:        Int       = 0
    var item:      OrderItem = OrderItem()
    var status:    Int       = 0
    var fromUser:  String    = ""
    var toUser:    String    = ""
    var thumbnail: UIImage?
    
    
    init(id: Int, item: OrderItem, status: Int, fromUser: String, toUser: String){
        self.id       = id
        self.item     = item
        self.status   = status
        self.fromUser = fromUser
        self.toUser   = toUser
    }
    
    
    init(dic: NSDictionary) {
        for elem in dic {
            switch (elem.key as String) {
                case "id":          self.id       = elem.value as Int
                case "status":      self.status   = elem.value as Int
                case "fromUser":    self.fromUser = elem.value as String
                case "toUser":      self.toUser   = elem.value as String
                case "item":        self.item     = OrderItem(dic: (elem.value as NSDictionary) )
                default:            println("Unknown element: \(elem.key as String)")
            }
        }
    }
    
    // Get url of an image (thumbnail).
    //
    // :param: name image filename with extension
    // :returns: NSURL
    func imageURL(name:String) -> NSURL {
        return NSURL(string: "http://beta.fancyswap.com/images/data/thumbs/\(name)")!
    }

}